cc.Class({
    extends: require("GameBase"),

    properties: {
        resource1:{
            default : null,
            type : cc.SpriteFrame,
        },
		resource3:{
            default : null,
            type : cc.SpriteFrame,
        },
		resource4:{
            default : null,
            type : cc.SpriteFrame,
        },
		canvas:{
			default:null,
			type:cc.Node
		},
		effectMast:{
			default:null,
			type:cc.Node
		},
		effectTop:{
			default:null,
			type:cc.Node
		},
		effectStar:{
			default:null,
			type:cc.Prefab
		},
		effectStarBig:{
			default:null,
			type:cc.Prefab
		},
		messageDisplay: {
            default: null,
            type: cc.Label
        },
		effectBoom:{
			default:null,
			type:cc.Prefab
		},
		goonDisplay: {
            default: null,
            type: cc.Label
        },
		backDisplay: {
            default: null,
            type: cc.Label
        },
    },
	

    onLoad: function () {
		
		this.initBaseGame(2);
		
		this.timeCutCallback = cc.callFunc(function () {
				this.cutTime();
		}, this);
		
		this.cutTimeForStart();
		
    },
	
	//开始倒计时
	cutTimeForStart(){
		
		this.timeCost = false;
		
		this.timeCut = 3;
		
		this.node.runAction(cc.sequence(cc.delayTime(1), this.timeCutCallback));
	},
	
	goon(){
		
		if(this.scoreadd>0){
				
			this.score+=this.scoreadd;
				
			this.showMessage("+ "+this.scoreadd);
				
			this.scoreadd = 0;
		}
		
		if(this.happyTime==0){
		if(this.gameOver()){
			
			return ;
			
		}else{
			
			if(this.mapManager.canMove(this)){
				this.timeCost = true;
				this.selectedBlock=null;
				this.selectedBlock2=null;
			}else{
				this.moveAll();
			}
		}
		}else{
			this.rewardManager.disappearDuringReward();
		}
	},
	
	timeOut(){
		this.effectMast.active=true;
		
		this.messageDisplay.node.stopAllActions();
		
		this.messageDisplay.node.setPosition(0,0);
		
		this.messageDisplay.string = '时间到！'
		
		this.messageDisplay.node.setScale(0.1);
		
		this.messageDisplay.node.runAction(cc.sequence(cc.scaleTo(0.2,1.5,1.5),cc.scaleTo(0.2,1,1)));
		
		//this.node.runAction(cc.sequence(cc.delayTime(2), this.toScoreCallback));
		
		this.happyTime=1;
		this.rewardManager.startReward();
	},
	
	cutTime(){
		
		if(this.timeCut>0){
		
			this.messageDisplay.node.setPosition(0,0);
		
			this.messageDisplay.string = this.timeCut;
		
			this.messageDisplay.node.setScale(3);
		
			this.messageDisplay.node.runAction(cc.sequence(cc.scaleTo(0.2,0.5,0.5),cc.scaleTo(0.2,1,1)));
		
			this.node.runAction(cc.sequence(cc.delayTime(0.8), this.timeCutCallback));
			
			this.timeCut--;
			
		}else{
			
			this.effectMast.active=false;		
		
			this.timeCost = true;
			
			this.messageDisplay.node.setScale(0);
			
		}
		
	},

	update (dt) {
		if(this.timeCost){
			this.lastStep--;
			this.usedStep++;
			
			if(this.usedStep>=3000&&this.usedStep<6000){
				this.shapeNmb=6;
			}else if(this.usedStep>=6000){
				this.shapNmb=7;
			}
			
			if(this.lastStep<=0){
				this.timeCost=false;
				this.timeOut();
			}
		}
	}
});
